package MyBlog.biz.impl;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import MyBlog.biz.CommentBiz;
import MyBlog.dao.CommentDao;
import MyBlog.entity.Comment;

@Service("commentBiz")
public class CommentBizImpl implements CommentBiz {

	@Autowired
	private CommentDao commentDao;

	@Override
	public List<Comment> getCommentsByArticleId(int articleId) {
		return commentDao.getCommentsByArticleId(articleId);
	}

	@Override
	public void add(Comment comment) {
		String ip;
		try {
			ip = InetAddress.getLocalHost().getHostAddress();
			Date currentDate = new Date(System.currentTimeMillis());
			comment.setCommentTime(currentDate);
			comment.setState(1);
			comment.setIp(ip);
			commentDao.add(comment);
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
	
}
